var AlfredNode = require('alfred-workflow-nodejs');
var actionHandler = AlfredNode.actionHandler;

var logger = require('winston');

var workflow = AlfredNode.workflow;
workflow.setName("nodejs-workflow-urls");

var utils = require('./AlfredWorkflowUtils.js');
var mysql = require('./AlfredWorkflowMysqlServer.js');
var moment = require('moment');

console.log(moment('2015-10-10 10:10:10','YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss'));

testUpdate();
testSelect();

		function testStringJsonFy(){
			var result ={recordsFiltered:0,recordsTotal:7,data:""};

			var s = JSON.stringify(result);   
			logger.info(s);
		}
		
		function testUpdate(){
			var params = [moment().toDate()];
			mysql.executeSql("update alfred_workflow_urls set create_time=? where id='4b6a49af-d50b-4834-abee-16a6327ff1f6' ", params).then(
					function(rows) {
						logger.info("rows affected:%s",rows.affectedRows);
					}).catch(function(err){
						logger.error(err);
					});
		}
	
		function testSelect(){
			mysql.executeSql("select * from alfred_workflow_urls where keyword like ? limit 1 ", "%b%").then(
					function(rows) {
						var result ={recordsFiltered:rows.length,recordsTotal:rows.length,data:rows};
						var s = JSON.stringify(result);   
						logger.info(s);
						rows.forEach(function(item, index, array) {
							logger.info(item);
						});
					}).catch(function(err){
						logger.error(err);
					});

		}
		function testSave(){
			executeSql("insert into alfred_workflow_urls set ? ", myUrlModel).then(
					function(rows) {
						rows.forEach(function(item, index, array) {
							logger.info(item);
						});
					}).catch(function(err){
						logger.error(err);
					});
		}
	